<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;

/**
 * 聊天记录表
 * Class ChatRecords
 * @package App\Models
 */
class ChatRecords extends Model
{
    use SoftDeletes;//软删除
    protected $guarded= [];
    //将字段值自动转成json,存的时候直接把数组给ROM就行,取值时框架会自动吧json转成数组
    protected $casts = [
        'content' => 'json',
    ];

    //改变时间格式
    protected function serializeDate(\DateTimeInterface $date)
    {
        return $date->format('Y-m-d H:i:s');
    }


    public function binding_records()
    {
        return $this->belongsTo(BindingRecord::class,'addressee_id','id');
    }


    public function comments(){
        return $this->hasMany(ChatRecords::class,'sender_id','sender_id');
    }

    public function binding_record()
    {
        return $this->belongsTo(BindingRecord::class,'sender_id','id');
    }
}
